package org.ax.controller.sys;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.ax.pojo.sys.Permission;
import org.ax.pojo.sys.User;
import org.ax.service.sys.PermissionService;
import org.ax.service.sys.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-23-16:12
 */
@Controller
@RequestMapping("/sys")
public class HomeController {
    @Autowired
    HttpSession httpSession;
    @Autowired
    UserService userService;
    @Autowired
    PermissionService permissionService;

    @RequiresPermissions("shouquan")
    @RequestMapping("/home")
    public String home(){
        Subject subject = SecurityUtils.getSubject();
        User user=(User)subject.getPrincipal();
        httpSession.setAttribute("user", user);
        Map<Permission, List<Permission>> permissionListMap = permissionService.permissionAll();
        httpSession.setAttribute("permissionListMap",permissionListMap);
        return "index";
    }

}
